package com.cnswhy.cloud.server.core.dao;

import com.cnswhy.cloud.common.core.base.mapper.SuperMapper;
import com.cnswhy.cloud.server.core.entity.CustomerPrivilege;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * Mapper 接口
 * 
 * </p>
 *
 * @author cnswhy
 * @date 2020-10-16
 */
@Repository
public interface CustomerPrivilegeMapper extends SuperMapper<CustomerPrivilege> {
    @Select("select ifnull(sum(give_num),0)-ifnull(sum(used_num),0) from t_customer_privilege  where price_id=#{priceId} and customer_id=#{customerId}")
    int queryCanUse(@Param("priceId") Long priceId,@Param("customerId") Long customerId);
    @Select("select * from t_customer_privilege  where price_id=#{priceId} and customer_id=#{customerId} order by give_num - used_num desc")
    List<CustomerPrivilege> queryCustomerPrivilegeList(@Param("priceId") Long priceId, @Param("customerId") Long customerId);


}
